proc getimage {version build platform outdeb} {
#!/usr/bin/expect -f
###############################################################################
# Copyright (c) 2004
# All rights reserved
#
# Fortinet Technologies (Canada) Ltd.
#
###############################################################################
#
# FILE NAME: getimage.tcl
#
# PROGRAMMER(S): Qing Xu 
#
# DATE CREATED: July 21, 2004
#
# DESCRIPTION: Download FortiOS images from image server
#
###############################################################################
#
# REVISION HISTORY:
#
# Date			Revision	Author				Description
# July 21, 2004	1.0		Qing Xu				Original
#
###############################################################################

###############################################################################
#
# Start Procedure
#
###############################################################################

#Set FortiOS Image server IP address
set server 172.16.100.71
set timeout -1
set image_dir /usr/tftpboot
#
#if { $argc < 3 } {
#	puts "Usage: getimage {v250|v280} {buildxxx} {platform1 platform2 ..}\n"
#	puts "platform can be choosen from:\n"
#	puts "		50,50A,60,60-WF,100,200,300,400,500,800,1K\n"
#	puts "		3000,3600,4000,5000\n"
#	puts "		3000-xvd, 4000-xvd, 5000-xvd\n"
#	puts "		where x is one of 5,25,50,100,250\n"
#	exit
#}
#
#set version [lindex $argv 0]
#set build [lindex $argv 1]
file mkdir $image_dir/$version/$build
cd $image_dir/$version/$build
#
set i 2
#
spawn ftp $server
#expect "root):"
expect "):"
exp_send "test\r"
expect "Password:"
exp_send "test\r"
expect "ftp>"
exp_send "cd FortiOS/$version/$build\r"
expect "ftp>"
exp_send "bin\r"
expect "ftp>"
while { $i < 3 } {
	set image $platform
	set list [split $image -]
	set platform [lindex $list 0]
	set vd [lindex $list 1]
	if { $vd == ""} {
		set filename FGT_$platform-$version-$build-FORTINET.$outdeb
		if { ![file exist $filename] } {
			exp_send "get $filename\r" 
			expect "ftp>"
		}
	} elseif { $vd == "WF" } {
		set filename FWF_$platform-$version-$build-FORTINET.$outdeb
		if { ![file exist $filename] } {
			exp_send "get $filename\r"
			expect "ftp>"
		}
	} else {
		set filename FGT_$platform-$version-$build-FORTINET-$vd.$outdeb
		if { ![file exist $filename] } {
			exp_send "get $filename\r"
			expect "ftp>"
		}
	}
	set i [ expr $i + 1 ]
}
exp_send "quit\r"
}
